function plot_local_function_2d(function_u, V)

min_x = min(V(:,1));
max_x = max(V(:,1));
min_y = min(V(:,2));
max_y = max(V(:,2));

switch size(V,1)
    case 3
        A = [min_x, 1;max_x, 1];
        b = [max_y, min_y]';
        r = A\b;
        if V(1,:) == [min_x, min_y]
            triangle_region = @(x,y) (x >= min_x) & (x <= max_x) & (y >= min_y) & (y <= max_y) & (y <= r(1)*x+r(2));
        else
            triangle_region = @(x,y) (x >= min_x) & (x <= max_x) & (y >= min_y) & (y <= max_y) & (y >= r(1)*x+r(2));
        end
        [x, y] = meshgrid(linspace(min_x, max_x, 100), linspace(min_y, max_y, 100));
        for i = 1:size(V,1)
            z = function_u(x, y);
            z(~triangle_region(x, y)) = NaN;
            surf(x, y, z);
            hold on;
        end
    case 4
        [x, y] = meshgrid(linspace(min_x, max_x, 100), linspace(min_y, max_y, 100));
        for i = 1:size(V,1)
            z = function_u(x, y);
            surf(x, y, z);
            hold on;
        end
    otherwise
        error("Invalid V");
end

end